//
//  MBDUploadGroupViewModel.swift
//  MasterBoy
//
//  Created by kyson on 2023/4/5.
//

import Foundation
import UIKit
import YYText


class MBDGroupTitleModel : NSObject {
    var title : String!
    var subtitle : String!
}



class MBDUploadGroupViewModel: NSObject {
    var cellModels:Array<Any>!
    var groupDetail : MBDGroupDetailModel?
    var isUpdate : Bool!

    var groupTypeDetailCellModel : MBDUploadGroupTypeDetailCellModel!
    var groupTypeCellModel : MBDUploadGroupTitleCellModel!
    var groupNameCellModel : MBDUploadGroupTitleCellModel!
    var groupNameDetailCellModel : MBDUploadGroupNameDetailCellModel!
    
    var groupOwnerTitleCellModel : MBDUploadGroupTitleCellModel!
    var groupOwnerDetailCellModel : MBDUploadGroupOwnerDetailCellModel!
    
    var groupDescTitleCellModel : MBDUploadGroupTitleCellModel!

    var groupDescCellModel : MBDUploadGroupDescCellModel!
    var groupLogoCellModel : MBDUploadGroupLogoCellModel!
    var groupQRCodeCellModel : MBDUploadGroupQRCodeCellModel!

    override init() {
        super.init()
        self.isUpdate = false
        self.generateData(groupDetail: nil)
    }
    
    init( groupDetail : MBDGroupDetailModel? = nil,isUpdate : Bool = false) {
        super.init()
        self.isUpdate = isUpdate
        
        self.groupDetail = groupDetail
        self.generateData(groupDetail: groupDetail)
    }
    
    private func generateData(groupDetail: MBDGroupDetailModel?) {
        var cellModels = [Any]()
        
        if (groupDetail != nil && groupDetail!.reason != nil && !groupDetail!.reason!.isBlank) {
            let groupTypeCellModel = MBDRejectReasonCellModel()
            groupTypeCellModel.reason = groupDetail!.reason
            cellModels.append(groupTypeCellModel)
        }
        
        let groupTypeCellModel = MBDUploadGroupTitleCellModel()
        self.groupTypeCellModel = groupTypeCellModel
        //群类型
        let groupTypeTitleModel = MBDGroupTitleModel()
        groupTypeTitleModel.title = "群类型"
        groupTypeTitleModel.subtitle = "必选 *"
        groupTypeCellModel.titleModel = groupTypeTitleModel
        
        cellModels.append(groupTypeCellModel)
        
        let groupTypeDetailCellModel = MBDUploadGroupTypeDetailCellModel()
        self.groupTypeDetailCellModel = groupTypeDetailCellModel
        if (nil != groupDetail) {
            groupTypeDetailCellModel.text = MBDUploadGroupTypeDetailCellModel.Wechat
        } else {
            groupTypeDetailCellModel.text = MBDUploadGroupTypeDetailCellModel.clickToSetGroupType
        }
        cellModels.append(groupTypeDetailCellModel)
        
        //title
        let groupNameCellModel = MBDUploadGroupTitleCellModel()

        //title model
        let groupNameTitleModel = MBDGroupTitleModel()
        groupNameTitleModel.title = "群名"
        groupNameTitleModel.subtitle = "必填 *"
        groupNameCellModel.titleModel = groupNameTitleModel
        
        self.groupNameCellModel = groupNameCellModel
        cellModels.append(groupNameCellModel)
        
        let groupNameDetailCellModel = MBDUploadGroupNameDetailCellModel()
        self.groupNameDetailCellModel = groupNameDetailCellModel
        if (nil != groupDetail) {
            groupNameDetailCellModel.text = groupDetail!.groupName
        } else {
            groupNameDetailCellModel.text = MBDUploadGroupNameDetailCellModel.clickToSetGroupName
        }
        cellModels.append(groupNameDetailCellModel)
        
        let groupOwnerTitleCellModel = MBDUploadGroupTitleCellModel()
        // model
        let groupOwnerTitleModel = MBDGroupTitleModel()
        groupOwnerTitleModel.title = "群主(或管理员)"
        groupOwnerTitleModel.subtitle = "必填 *"
        groupOwnerTitleCellModel.titleModel = groupOwnerTitleModel
        
        self.groupOwnerTitleCellModel = groupOwnerTitleCellModel
        cellModels.append(groupOwnerTitleCellModel)
        
        let groupOwnerDetailCellModel = MBDUploadGroupOwnerDetailCellModel()
        self.groupOwnerDetailCellModel = groupOwnerDetailCellModel
        if (nil != groupDetail) {
            groupOwnerDetailCellModel.text = groupDetail!.groupManager
        } else {
            groupOwnerDetailCellModel.text = MBDUploadGroupOwnerDetailCellModel.clickToSetGroupOwner
        }
        cellModels.append(groupOwnerDetailCellModel)
        
        let groupLogoCellModel = MBDUploadGroupTitleCellModel()
        
        //title model
        let groupLogoTitleModel = MBDGroupTitleModel()
        groupLogoTitleModel.title = "群 Logo"
        groupLogoTitleModel.subtitle = "必须 *"
        groupLogoCellModel.titleModel = groupLogoTitleModel
        
        cellModels.append(groupLogoCellModel)
        
        let groupLogoDetailCellModel = MBDUploadGroupLogoCellModel()
        if (nil != groupDetail) {
            groupLogoDetailCellModel.logoPath = groupDetail!.groupLogo
        } else {
            groupLogoDetailCellModel.logoPath = MBDUploadGroupLogoCellModel.clickToSetGroupLogo
        }
        self.groupLogoCellModel = groupLogoDetailCellModel
        cellModels.append(groupLogoDetailCellModel)

        let groupDescTitleCellModel = MBDUploadGroupTitleCellModel()
        self.groupDescTitleCellModel = groupDescTitleCellModel
        //title model
        let groupDescTitleModel = MBDGroupTitleModel()
        groupDescTitleModel.title = "群描述"
        groupDescTitleModel.subtitle = "必填 *"
        groupDescTitleCellModel.titleModel = groupDescTitleModel
        
        cellModels.append(groupDescTitleCellModel)
        
        let groupDescCellModel = MBDUploadGroupDescCellModel()
        self.groupDescCellModel = groupDescCellModel
        if (nil != groupDetail) {
            groupDescCellModel.text = groupDetail!.groupDesc
        } else {
            groupDescCellModel.text = MBDUploadGroupDescCellModel.clickToSetGroupDesc
        }
        cellModels.append(groupDescCellModel)
        
        let groupQRCodeTitleCellModel = MBDUploadGroupTitleCellModel()
//        self.groupDescTitleCellModel = groupDescTitleCellModel
        //title model
        let groupQRCodeTitleModel = MBDGroupTitleModel()
        groupQRCodeTitleModel.title = "群二维码"
        groupQRCodeTitleModel.subtitle = " "
        groupQRCodeTitleCellModel.titleModel = groupQRCodeTitleModel
        
        cellModels.append(groupQRCodeTitleCellModel)
        
        let groupQRCodeCellModel = MBDUploadGroupQRCodeCellModel()
        self.groupQRCodeCellModel = groupQRCodeCellModel
        
        if (nil != groupDetail) {
            groupQRCodeCellModel.qrCodePath = groupDetail!.groupCodeUrl
            groupQRCodeCellModel.praisedQRCode = groupDetail!.praisedQrUrl
        } else {
            groupQRCodeCellModel.qrCodePath = MBDUploadGroupQRCodeCellModel.clickToSetGroupQRCode
        }
        
        cellModels.append(groupQRCodeCellModel)
        
        
        self.cellModels = cellModels
    }
}
